package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.anno.AutoFill;
import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

@Mapper
public interface DishMapper {

    /**
     * 根据分类id查询菜品数量
     * @param categoryId
     * @return
     */
    @Select("select count(id) from dish where category_id = #{categoryId}")
    Integer countByCategoryId(Long categoryId);

    /**
     * 新增菜品
     * @param dish
     */
    @AutoFill(OperationType.INSERT)
    void insertDish(Dish dish);

    /**
     * 分页条件查询(需要外连接,将dish表与category表联合查询)
     * @param dto
     * @return
     */
    Page<DishVO> pageSelect(DishPageQueryDTO dto);

    /**
     * 根据id删除菜品
     * @param ids
     */
    void delete(List<Long> ids);

    /**
     * 根据id查找菜品
     * @param dishId
     * @return
     */
    @Select("select *from dish where id=#{dishId}")
    Dish selectById(Long dishId);

    /**
     * 修改菜品信息
     * @param dish
     */
    @AutoFill(OperationType.UPDATE)
    void updateDish(Dish dish);

    /**
     *新增套餐-根据categoryId查询菜品
     * @param dish
     * @return
     */
    List<Dish> dishlist(Dish dish);

    /**
     * 根据setmealId查询对应的菜品(联立dish与setmeal_dish)
     * @param setmealId
     * @return
     */
    @Select("select a.* from dish a left outer join setmeal_dish b on a.id = b.dish_id where b.setmeal_id =#{setmealId} ")
    List<Dish> selectDishBySetmealId(Long setmealId);

    /**
     * 根据状态统计菜品数量
     * @param map
     * @return
     */
    Integer getStatusDishCount(Map map);
}
